package com.tanhua.app.controller;

import com.aliyuncs.exceptions.ClientException;
import com.tanhua.api.db.UserInfoApi;
import com.tanhua.app.service.BaiduService;
import com.tanhua.app.service.RecommendService;
import com.tanhua.app.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping(value = "/tanhua")
public class TanHuaController {

    @Autowired
    private RecommendService recommendService;

    @Autowired
    private UserService userService;

    @GetMapping(value = "/{id}/love",name = "探花-不喜欢")
    public ResponseEntity love(@PathVariable(value = "id")Long cardUserId){
        return userService.love(cardUserId);
    }

    @GetMapping(value = "/{id}/unlove",name = "探花-不喜欢")
    public ResponseEntity unlove(@PathVariable(value = "id")Long cardUserId){
        return userService.unlove(cardUserId);
    }

    @GetMapping(value = "/cards",name = "探花-左滑右滑")
    public ResponseEntity cards(){
        return userService.cards();
    }

    @GetMapping(value = "/todayBest", name = "查询今日佳人")
    public ResponseEntity todayBest() throws ClientException {
        return recommendService.findMaxScore();
    }

    @GetMapping(value = "/recommendation", name = "查询多个推荐佳人")
    public ResponseEntity findScorePage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pagesize) throws ClientException {
        return recommendService.findScorePage(page,pagesize);
    }


    @GetMapping(value = "/{id}/personalInfo", name = "查询佳人个人信息展示")
    public ResponseEntity personalInfo(@PathVariable("id") Long jrid) throws ClientException {
        return recommendService.personalInfo(jrid);
    }

    @GetMapping(value = "/strangerQuestions", name = "查询佳人的问题")
    public ResponseEntity strangerQuestions(Long userId) throws ClientException {
        return recommendService.strangerQuestions(userId);
    }

    @PostMapping(value = "/strangerQuestions", name = "回复佳人的问题")
    public ResponseEntity toStrangerQuestions(@RequestBody Map<String,String> map) throws ClientException {
        // 给谁发 107
        Integer toUserId =Integer.parseInt(map.get("userId"));
        // 发的内容 55
        String reply = map.get("reply");

        return recommendService.toStrangerQuestions(toUserId,reply);
    }

    @Autowired
    private BaiduService baiduService;

    @GetMapping(value = "/search", name = "搜附近")
    public ResponseEntity search(String gender,Integer distance) throws ClientException {

        return baiduService.search(gender,distance);
    }
}
